﻿using System.Collections.Generic;
using System.Net.WebSockets;
using System.Threading.Tasks;

namespace ZilLion.Service.Core.Infrastructure.Middleware.WebSocket.Interface
{
    public interface IWebSocketHandler
    {
        Task ReceiveAsync(System.Net.WebSockets.WebSocket socket, WebSocketReceiveResult result,
            string messageJson);

        /// <summary>
        ///     当连接建立时
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        Task OnConnected(System.Net.WebSockets.WebSocket socket);

        /// <summary>
        ///     链接断开
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        Task OnDisconnected(System.Net.WebSockets.WebSocket socket);

        /// <summary>
        ///     发送消息
        /// </summary>
        /// <param name="socket">soket 对象</param>
        /// <param name="socketMessage">消息</param>
        /// <returns></returns>
        Task SendMessageAsync(System.Net.WebSockets.WebSocket socket, SocketMessage socketMessage);

        /// <summary>
        ///     发送消息(从全局字典中通过ID 找到socket 对象)
        /// </summary>
        /// <param name="socketId"></param>
        /// <param name="socketMessage"></param>
        /// <returns></returns>
        Task SendMessageAsync(string socketId, SocketMessage socketMessage);

        /// <summary>
        ///     广播发送全部消息
        /// </summary>
        /// <param name="socketMessage"></param>
        /// <returns></returns>
        Task SendMessageToAllAsync(SocketMessage socketMessage);

        /// <summary>
        ///     按照分组来发送消息
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="socketMessage"></param>
        /// <returns></returns>
        Task SendMessageToGroupAsync(string groupId, SocketMessage socketMessage);

        /// <summary>
        ///     按照分组发送消息(第三个参数是例外)
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="socketMessage"></param>
        /// <param name="exceptgroupId"></param>
        /// <returns></returns>
        Task SendMessageToGroupAsync(string groupId, SocketMessage socketMessage, IList<string> exceptgroupId);
    }
}